<?php

namespace App\Http\Models;

/**
 * Class Users
 * @package App\Http\Models
 *
 * @property  integer id
 *
 * @property  string username
 *
 * @property  string nickname
 *
 * @property  string mobile
 *
 * @property  string email
 *
 * @property  string avatar
 *
 * @property  string password
 *
 * @property  string salt
 *
 * @property  string token
 *
 * @property  integer status
 *
 * @property  string created_at
 *
 * @property  string updated_at
 */
class Users extends Model
{
    protected $table = 'users';
    /**
     * 运行填充的字段
     * @var array
     */
    protected $fillable = ['username', 'nickname', 'mobile', 'email', 'avatar', 'password', 'salt', 'token', 'status'];

    /**
     * 验证规则
     * @param $data
     * @return array
     */
    public function rules($data)
    {

        $id = isset($data["id"]) ? $data["id"] : null;

        return [
            'username' => 'required|max:50|unique:users,username,' . $id,

            'nickname' => 'max:50',

            'mobile' => 'required|max:13|unique:users,mobile,' . $id,

            'email' => 'required|max:100|unique:users,email,' . $id,

            'avatar' => 'max:255',

            'password' => 'required|max:255',

            'salt' => 'required|max:50',

            'token' => 'max:250',

            'status' => 'max:4',
            'repassword' => 'required|same:password',
        ];
    }

    /**
     * 字段名称
     * @var array
     */
    public $attribute = [
        'id' => '',

        'username' => '用户名',

        'nickname' => '用户昵称',

        'mobile' => '用户手机',

        'email' => '邮箱',

        'avatar' => '头像',

        'password' => '密码',

        'salt' => '盐',

        'token' => 'token',

        'status' => '用户状态 1 正常 2 拉黑',

        'created_at' => '创建时间',

        'updated_at' => '更新时间',
    ];

    /**
     * 默认值
     * @var array
     */
    public $attributes = [
        'status' => '1',
    ];

    public function fillModel(){
        return [
            'id'=>$this->id,
            'username'=>$this->username,
            'status'=>$this->status,
        ];
    }

}
